package com.base.demo.viewmodel

import android.app.Application
import androidx.lifecycle.asLiveData
import androidx.lifecycle.viewModelScope
import com.base.common.BaseApplication
import com.base.common.viewmodel.BaseViewModel
import com.base.demo.data.Login
import com.base.demo.repository.DemoRepository
import com.kotlin.base.net.request
import com.tao.data.Resource
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class DemoViewModel @Inject constructor(application: Application,private  val repository: DemoRepository) :BaseViewModel(application) {

   private var _stateView: MutableStateFlow<Resource<Login>> = MutableStateFlow(Resource.Start())

    val  dataDemo=_stateView.asStateFlow()
    val  liveData=_stateView.asLiveData()



      fun getData(){

          viewModelScope.launch {
              request(repository.getData(),_stateView)
          }


      }




}